home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / gpp-1_42.lha / g++-1.42.0 / cplus-tree.c < prev    next >
C/C++ Source or Header  |  1991-10-19  |  37KB  |  1,337 lines

  1. /* Language-depednent node constructors for parse phase of GNU compiler.
  2.    Copyright (C) 1987, 1988 Free Software Foundation, Inc.
  3.    Hacked by Michael Tiemann (tiemann@mcc.com)
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 1, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #include "config.h"
  22. #include <stdio.h>
  23. #include "obstack.h"
  24. #include "tree.h"
  25. #include "cplus-tree.h"
  26. #include "flags.h"
  27. #include "assert.h"
  28.  
  29. #define MAX(x,y) ((x) > (y) ? (x) : (y))
  30. #define MIN(x,y) ((x) < (y) ? (x) : (y))
  31. #define CEIL(x,y) (((x) + (y) - 1) / (y))
  32.  
  33. /* Return nonzero if REF is an lvalue valid for this language.
  34.    Lvalues can be assigned, unless they have TREE_READONLY.
  35.    Lvalues can have their address taken, unless they have TREE_REGDECL.  */
  36.  
  37. int
  38. lvalue_p (ref)
  39.      tree ref;
  40. {
  41.   register enum tree_code code = TREE_CODE (ref);
  42.  
  43.   if (language_lvalue_valid (ref))
  44.     switch (code)
  45.       {
  46.       case COMPONENT_REF:
  47.     return lvalue_p (TREE_OPERAND (ref, 0));
  48.  
  49.       case STRING_CST:
  50.     return 1;
  51.  
  52.       case VAR_DECL:
  53.     if (TREE_READONLY (ref) && ! TREE_STATIC (ref)
  54.         && DECL_LANG_SPECIFIC (ref)
  55.         && DECL_IN_AGGR_P (ref))
  56.       return 0;
  57.       case INDIRECT_REF:
  58.       case ARRAY_REF:
  59.       case PARM_DECL:
  60.       case RESULT_DECL:
  61.       case ERROR_MARK:
  62.     if (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE
  63.         && TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE)
  64.       return 1;
  65.     break;
  66.  
  67.       case NEW_EXPR:
  68.     return 1;
  69.  
  70.       case CALL_EXPR:
  71.     if (TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE
  72.         /* unary_complex_lvalue knows how to deal with this case.  */
  73.         || TREE_ADDRESSABLE (TREE_TYPE (ref)))
  74.       return 1;
  75.     break;
  76.  
  77.     /* A currently unresolved scope ref.  */
  78.       case SCOPE_REF:
  79.     abort ();
  80.       case OFFSET_REF:
  81.     if (TREE_CODE (TREE_OPERAND (ref, 1)) == FUNCTION_DECL)
  82.       return 1;
  83.     if (TREE_CODE (TREE_OPERAND (ref, 1)) == VAR_DECL)
  84.       if (TREE_READONLY (ref) && ! TREE_STATIC (ref)
  85.           && DECL_LANG_SPECIFIC (ref)
  86.           && DECL_IN_AGGR_P (ref))
  87.         return 0;
  88.       else
  89.         return 1;
  90.     break;
  91.       }
  92.   return 0;
  93. }
  94.  
  95. /* Return nonzero if REF is an lvalue valid for this language;
  96.    otherwise, print an error message and return zero.  */
  97.  
  98. int
  99. lvalue_or_else (ref, string)
  100.      tree ref;
  101.      char *string;
  102. {
  103.   int win = lvalue_p (ref);
  104.   if (! win)
  105.     error ("invalid lvalue in %s", string);
  106.   return win;
  107. }
  108.  
  109. /* INIT is a CALL_EXPR which needs info about its target.
  110.    TYPE is the type that this initialization should appear to have.
  111.  
  112.    Build an encapsulation of the initialization to perform
  113.    and return it so that it can be processed by language-independent
  114.    and language-specific expression expanders.
  115.  
  116.    If WITH_CLEANUP_P is nonzero, we build a cleanup for this expression.
  117.    Otherwise, cleanups are not built here.  For example, when building
  118.    an initialization for a stack slot, since the called function handles
  119.    the cleanup, we would not want to do it here.  */
  120. tree
  121. build_cplus_new (type, init, with_cleanup_p)
  122.      tree type;
  123.      tree init;
  124.      int with_cleanup_p;
  125. {
  126.   tree slot = build (VAR_DECL, type);
  127.   tree rval = build (CPLUS_NEW_EXPR, type,
  128.              TREE_OPERAND (init, 0), TREE_OPERAND (init, 1), slot);
  129.   TREE_ADDRESSABLE (rval) = 1;
  130.   rval = build (NEW_EXPR, type, slot, rval, 0);
  131.   TREE_VOLATILE (rval) = 1;
  132.   TREE_ADDRESSABLE (rval) = 1;
  133.  
  134.   if (with_cleanup_p && TYPE_NEEDS_DESTRUCTOR (type))
  135.     rval = build (WITH_CLEANUP_EXPR, type, rval, 0,
  136.           build_delete (TYPE_POINTER_TO (type),
  137.                 build_unary_op (ADDR_EXPR, slot, 0),
  138.                 integer_two_node,
  139.                 LOOKUP_NORMAL|LOOKUP_DESTRUCTOR|LOOKUP_NONVIRTUAL, 0));
  140.  
  141.   TREE_VOLATILE (rval) = 1;
  142.   return rval;
  143. }
  144.  
  145. extern struct obstack *current_obstack;
  146. extern struct obstack permanent_obstack, class_obstack;
  147. extern struct obstack *saveable_obstack;
  148.  
  149. /* Return a type like TYPE except that its CLASSTYPE_OFFSET
  150.    is OFFSET.
  151.  
  152.    Such variant types already made are recorded so that duplicates
  153.    are not made.
  154.  
  155.    A variant types should never be used as the type of an expression.
  156.    Use TYPE_MAIN_VARIANT to find the main variant.  */
  157.  
  158. tree
  159. build_classtype_variant (type, offset, virtualp)
  160.      tree type;
  161.      tree offset;
  162.      int virtualp;
  163. {
  164.   register tree t, m = CLASSTYPE_MAIN_VARIANT (type);
  165.   register struct obstack *ambient_obstack = current_obstack;
  166.   register struct obstack *ambient_saveable_obstack = saveable_obstack;
  167.   register int lo = TREE_INT_CST_LOW (offset);
  168.   register int hi = TREE_INT_CST_HIGH (offset);
  169.   /* First search the chain variants for one that is what we want.  */
  170.  
  171.   if (hi == 0 && lo == 0)
  172.     offset = integer_zero_node;
  173.  
  174.   for (t = m; t; t = CLASSTYPE_NEXT_VARIANT (t))
  175.     if (virtualp == TREE_VIA_VIRTUAL (t)
  176.     && lo == TREE_INT_CST_LOW (CLASSTYPE_OFFSET (t))
  177.     && hi == TREE_INT_CST_HIGH (CLASSTYPE_OFFSET (t)))
  178.       return t;
  179.  
  180.   /* We need a new one.  */
  181.   if (TREE_PERMANENT (type))
  182.     saveable_obstack = &permanent_obstack;
  183.   current_obstack = saveable_obstack;
  184.  
  185.   t = copy_node (type);
  186.   copy_type_lang_specific (t);
  187.   CLASSTYPE_AS_LIST (t) = build_tree_list (NULL_TREE, t);
  188.  
  189.   TYPE_POINTER_TO (t) = 0;
  190.   TYPE_REFERENCE_TO (t) = 0;
  191.   CLASSTYPE_OFFSET (t) = offset;
  192.   TREE_VIA_VIRTUAL (t) = virtualp;
  193.  
  194.   /* Always promise to have TYPE_POINTER_TO filled in.  */
  195.   build_pointer_type (t);
  196.  
  197.   /* Add this type to the chain of variants of TYPE.  */
  198.   CLASSTYPE_NEXT_VARIANT (t) = CLASSTYPE_NEXT_VARIANT (m);
  199.   CLASSTYPE_NEXT_VARIANT (m) = t;
  200.  
  201.   current_obstack = ambient_obstack;
  202.   saveable_obstack = ambient_saveable_obstack;
  203.   return t;
  204. }
  205.  
  206. /* Here is how primitive or already-canonicalized types' hash
  207.    codes are made.  MUST BE CONSISTENT WITH tree.c !!! */
  208. #define TYPE_HASH(TYPE) TREE_UID (TYPE)
  209.  
  210. /* Construct, lay out and return the type of methods belonging to class
  211.    BASETYPE and whose arguments and values are described by TYPE.
  212.    If that type exists already, reuse it.
  213.    TYPE must be a FUNCTION_TYPE node.  */
  214.  
  215. tree
  216. build_cplus_method_type (basetype, rettype, argtypes)
  217.      tree basetype, rettype, argtypes;
  218. {
  219.   register tree t;
  220.   tree ptype = build_pointer_type (basetype);
  221.   int hashcode;
  222.  
  223.   /* Make a node of the sort we want.  */
  224.   t = make_node (METHOD_TYPE);
  225.  
  226.   TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
  227.   TREE_TYPE (t) = rettype;
  228.   ptype = build_type_variant (ptype, !flag_this_is_variable, 0);
  229.  
  230.   /* The actual arglist for this function includes a "hidden" argument
  231.      which is "this".  Put it into the list of argument types.  */
  232.  
  233.   TYPE_ARG_TYPES (t) = tree_cons (NULL, ptype, argtypes);
  234.  
  235.   /* If we already have such a type, use the old one and free this one.
  236.      Note that it also frees up the above cons cell if found.  */
  237.   hashcode = TYPE_HASH (basetype) + TYPE_HASH (rettype) + type_hash_list (argtypes);
  238.   t = type_hash_canon (hashcode, t);
  239.  
  240.   if (TYPE_SIZE (t) == 0)
  241.     layout_type (t);
  242.  
  243.   return t;
  244. }
  245.  
  246. tree
  247. build_cplus_array_type (elt_type, index_type)
  248.      tree elt_type;
  249.      tree index_type;
  250. {
  251.   register struct obstack *ambient_obstack = current_obstack;
  252.   register struct obstack *ambient_saveable_obstack = saveable_obstack;
  253.   tree t;
  254.  
  255.   /* We need a new one.  If ELT_TYPE is permanent, make this permanent too.  */
  256.   if (TREE_PERMANENT (elt_type))
  257.     {
  258.       current_obstack = &permanent_obstack;
  259.       saveable_obstack = &permanent_obstack;
  260.     }
  261.  
  262.   t = build_array_type (elt_type, index_type);
  263.  
  264.   /* Push these needs up so that initialization takes place
  265.      more easily.  */
  266.   TYPE_NEEDS_CONSTRUCTING (t) = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type));
  267.   TYPE_NEEDS_DESTRUCTOR (t) = TYPE_NEEDS_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type));
  268.   current_obstack = ambient_obstack;
  269.   saveable_obstack = ambient_saveable_obstack;
  270.   return t;
  271. }
  272.  
  273. /* This is temporary until later.  */
  274. /* Construct, lay out and return the type of objects which are of type TYPE
  275.    as members of type BASETYPE.  If that type exists already, reuse it.  */
  276. tree
  277. build_member_type (basetype, type)
  278.      tree basetype, type;
  279. {
  280.   register tree t;
  281.   int hashcode;
  282.  
  283.   assert (TREE_CODE (type) != FUNCTION_TYPE);
  284.  
  285.   /* Make a node of the sort we want.  */
  286.   t = make_node (OFFSET_TYPE);
  287.   TYPE_OFFSET_BASETYPE (t) = basetype;
  288.   TREE_TYPE (t) = type;
  289.   hashcode = TREE_UID (basetype) + TREE_UID (type);
  290.   t = type_hash_canon (hashcode, t);
  291.  
  292.   return t;
  293. }
  294.  
  295. /* Compute the actual offsets that our virtual base classes
  296.    will have *for this type*.  This must be performed after
  297.    the fields are laid out, since virtual baseclasses must
  298.    lay down at the end of the record.
  299.  
  300.    Returns the maximum number of virtual functions any of the virtual
  301.    baseclasses provide.  */
  302. int
  303. layout_vbasetypes (rec, max)
  304.      tree rec;
  305.      int max;
  306. {
  307.   /* Get all the virtual base types that this type uses.
  308.      The TREE_VALUE slot holds the virtual baseclass type.  */
  309.   tree vbase_types = get_vbase_types (rec);
  310.  
  311. #ifdef STRUCTURE_SIZE_BOUNDARY
  312.   int record_align = MAX (STRUCTURE_SIZE_BOUNDARY, TYPE_ALIGN (rec));
  313. #else
  314.   int record_align = MAX (BITS_PER_UNIT, TYPE_ALIGN (rec));
  315. #endif
  316.  
  317.   /* Record size so far is CONST_SIZE + VAR_SIZE * SIZE_UNIT bits,
  318.      where CONST_SIZE is an integer
  319.      and VAR_SIZE is a tree expression.
  320.      If VAR_SIZE is null, the size is just CONST_SIZE.
  321.      Naturally we try to avoid using VAR_SIZE.  */
  322.   register int const_size = 0;
  323.   register tree var_size = 0;
  324.   register int size_unit = BITS_PER_UNIT;
  325.   int nonvirtual_const_size;
  326.   tree nonvirtual_var_size;
  327.  
  328.   CLASSTYPE_VBASECLASSES (rec) = vbase_types;
  329.  
  330.   if (TREE_CODE (TYPE_SIZE (rec)) == INTEGER_CST)
  331.     const_size = TREE_INT_CST_LOW (TYPE_SIZE (rec)) * TYPE_SIZE_UNIT (rec);
  332.   else
  333.     {
  334.       var_size = TYPE_SIZE (rec);
  335.       size_unit = record_align;
  336.     }
  337.  
  338.   nonvirtual_const_size = const_size;
  339.   nonvirtual_var_size = var_size;
  340.  
  341.   while (vbase_types)
  342.     {
  343.       int inc;
  344.       tree basetype = ASSOC_TYPE (vbase_types);
  345.       tree offset;
  346.  
  347.       if (const_size == 0)
  348.     offset = integer_zero_node;
  349.       else
  350.     offset = convert_units (build_int (const_size), 1, BITS_PER_UNIT);
  351.  
  352.       if (CLASSTYPE_VSIZE (basetype) > max)
  353.     max = CLASSTYPE_VSIZE (basetype);
  354.       ASSOC_OFFSET (vbase_types) = offset;
  355.  
  356.       inc = MAX (record_align,
  357.          (TREE_INT_CST_LOW (TYPE_SIZE (basetype))
  358.           - TREE_INT_CST_LOW (CLASSTYPE_VBASE_SIZE (basetype)))
  359.          * TYPE_SIZE_UNIT (basetype));
  360.  
  361.       const_size += inc;
  362.       vbase_types = TREE_CHAIN (vbase_types);
  363.     }
  364.  
  365.   if (const_size - nonvirtual_const_size)
  366.     {
  367.       CLASSTYPE_VBASE_SIZE (rec) = convert_units (build_int (const_size - nonvirtual_const_size),
  368.                           1, BITS_PER_UNIT);
  369.       TYPE_SIZE (rec) = convert_units (build_int (const_size), 1, BITS_PER_UNIT);
  370.     }
  371.   else
  372.     CLASSTYPE_VBASE_SIZE (rec) = integer_zero_node;
  373.   return max;
  374. }
  375.  
  376. #if 0
  377. /* This function should never be needed.  */
  378. void
  379. fixup_vbase_offsets (type)
  380.      tree type;
  381. {
  382.   tree virtuals = TREE_CHAIN (CLASS_ASSOC_VIRTUALS (type));
  383.  
  384.   while (virtuals)
  385.     {
  386.       tree pfn = FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals));
  387.       tree decl = TREE_OPERAND (pfn, 0);
  388.       tree vcontext = get_base_type (DECL_VCONTEXT (decl), DECL_CONTEXT (decl), 0);
  389.       if (vcontext != NULL_TREE && TREE_VIA_VIRTUAL (vcontext))
  390.     {
  391.       tree offset;
  392.       tree vbase_offset_info;
  393.       tree parent_type;
  394.  
  395.       if (DECL_CONTEXT (decl) == TYPE_MAIN_VARIANT (type))
  396.         parent_type = type;
  397.       else
  398.         {
  399.           parent_type = get_base_type (DECL_CONTEXT (decl), type, 0);
  400.           if (parent_type == 0)
  401.         parent_type = type;
  402.         }
  403.       vbase_offset_info = value_member (vcontext,
  404.                         CLASSTYPE_VBASECLASSES (parent_type));
  405.       offset = genop (MINUS_EXPR, CLASSTYPE_OFFSET (parent_type),
  406.               TREE_PURPOSE (vbase_offset_info));
  407.       TREE_VALUE (virtuals) = build_vtable_entry (offset, pfn);
  408.     }
  409.       virtuals = TREE_CHAIN (virtuals);
  410.     }
  411. }
  412. #endif
  413.  
  414. /* Lay out the base types of a record type, REC.
  415.    Tentatively set the size and alignment of REC
  416.    according to the base types alone.
  417.  
  418.    Returns list of virtual base classes in a FIELD_DECL chain.  */
  419. tree
  420. layout_basetypes (rec)
  421.      tree rec;
  422. {
  423.   /* Chain to hold all the new FIELD_DECLs which point at virtual
  424.      base classes.  */
  425.   tree vbase_decls = NULL_TREE;
  426.  
  427. #ifdef STRUCTURE_SIZE_BOUNDARY
  428.   int record_align = MAX (STRUCTURE_SIZE_BOUNDARY, TYPE_ALIGN (rec));
  429. #else
  430.   int record_align = MAX (BITS_PER_UNIT, TYPE_ALIGN (rec));
  431. #endif
  432.  
  433.   /* Record size so far is CONST_SIZE + VAR_SIZE * SIZE_UNIT bits,
  434.      where CONST_SIZE is an integer
  435.      and VAR_SIZE is a tree expression.
  436.      If VAR_SIZE is null, the size is just CONST_SIZE.
  437.      Naturally we try to avoid using VAR_SIZE.  */
  438.   register int const_size = 0;
  439.   register tree var_size = 0;
  440.   register int size_unit = BITS_PER_UNIT;
  441.   int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (rec);
  442.  
  443.   /* Handle basetypes almost like fields, but record their
  444.      offsets differently.  */
  445.  
  446.   for (i = 1; i <= n_baseclasses; i++)
  447.     {
  448.       int inc, desired_align;
  449.       register tree basetype = CLASSTYPE_BASECLASS (rec, i);
  450.       tree decl;
  451.  
  452.       if (TYPE_SIZE (basetype) == 0)
  453.     {
  454.       error_with_aggr_type (basetype, "base class `%s' has incomplete type");
  455.       SET_CLASSTYPE_VIAS (rec, i, 1, 0);
  456.       continue;
  457.     }
  458.  
  459.       /* All basetypes are recorded in the association list of the
  460.      derived type.  */
  461.  
  462.       if (CLASSTYPE_VIA_VIRTUAL (rec, i))
  463.     {
  464.       int j;
  465.       char *name = (char *)alloca (TYPE_NAME_LENGTH (basetype)
  466.                        + sizeof (VBASE_NAME) + 1);
  467.       sprintf (name, VBASE_NAME_FORMAT, TYPE_NAME_STRING (basetype));
  468.  
  469.       /* The offset for a virtual base class is only
  470.          used in computing virtual function tables and
  471.          for initializing virtual base pointers.  The assoc
  472.          for this base type is built once `get_vbase_types'
  473.          is called.  */
  474.       CLASSTYPE_BASECLASS (rec, i) = basetype
  475.         = build_classtype_variant (basetype, integer_zero_node, 1);
  476.  
  477.       /* If this basetype can come from another vbase pointer
  478.          without an additional indirection, we will share
  479.          that pointer.  If an indirection is involved, we
  480.          make our own pointer.  */
  481.       for (j = 1; j <= n_baseclasses; j++)
  482.         if (! CLASSTYPE_VIA_VIRTUAL (rec, j)
  483.         && TYPE_USES_VIRTUAL_BASECLASSES (CLASSTYPE_BASECLASS (rec, j))
  484.         && value_member (TYPE_MAIN_VARIANT (basetype),
  485.                  CLASSTYPE_VBASECLASSES (CLASSTYPE_BASECLASS (rec, j))))
  486.           {
  487.         goto got_it;
  488.           }
  489.  
  490.       decl = build_lang_decl (FIELD_DECL, get_identifier (name),
  491.                   build_pointer_type (basetype));
  492.       DECL_FIELD_CONTEXT (decl) = rec;
  493.       SET_DECL_FCONTEXT (decl, TYPE_MAIN_VARIANT (basetype));
  494.       DECL_VBASE_P (decl) = 1;
  495.       TREE_CHAIN (decl) = vbase_decls;
  496.       vbase_decls = decl;
  497.  
  498.     got_it:
  499.       /* The space this decl occupies has already been accounted for.  */
  500.       continue;
  501.     }
  502.       else
  503.     {
  504.       tree class_offset;
  505.       tree assoc;
  506.  
  507.       if (const_size == 0)
  508.         class_offset = integer_zero_node;
  509.       else
  510.         {
  511.           /* Give each base type the alignment it wants.  */
  512.           const_size = CEIL (const_size, TYPE_ALIGN (basetype))
  513.         * TYPE_ALIGN (basetype);
  514.           class_offset = convert_units (build_int (const_size), 1, BITS_PER_UNIT);
  515.           CLASSTYPE_BASECLASS (rec, i) = basetype
  516.         = build_classtype_variant (basetype, class_offset, 0);
  517.         }
  518.  
  519.       if (CLASSTYPE_VSIZE (basetype))
  520.         assoc = make_assoc (class_offset, basetype,
  521.                 CLASS_ASSOC_VTABLE (basetype),
  522.                 CLASS_ASSOC_VIRTUALS (basetype),
  523.                 CLASSTYPE_ASSOC (rec));
  524.       else
  525.         assoc = make_assoc (class_offset, basetype, 0, 0,
  526.                 CLASSTYPE_ASSOC (rec));
  527.       CLASSTYPE_ASSOC (rec) = assoc;
  528.       if (const_size != 0)
  529.         {
  530.           TYPE_NAME (basetype) = copy_node (TYPE_NAME (basetype));
  531.           TREE_TYPE (TYPE_NAME (basetype)) = basetype;
  532.           DECL_OFFSET (TYPE_NAME (basetype)) = const_size;
  533.         }
  534.     }
  535.  
  536.       /* Add only the amount of storage not present in
  537.      the virtual baseclasses.  */
  538.       inc = MAX (record_align,
  539.          (TREE_INT_CST_LOW (TYPE_SIZE (basetype))
  540.           - TREE_INT_CST_LOW (CLASSTYPE_VBASE_SIZE (basetype)))
  541.          * TYPE_SIZE_UNIT (basetype));
  542.  
  543.       /* Record must have at least as much alignment as any field.  */
  544.       desired_align = TYPE_ALIGN (basetype);
  545.       record_align = MAX (record_align, desired_align);
  546.  
  547.       const_size += inc;
  548.     }
  549.  
  550.   if (const_size)
  551.     CLASSTYPE_SIZE (rec) = build_int_2 (const_size, 0);
  552.   else
  553.     CLASSTYPE_SIZE (rec) = integer_zero_node;
  554.   CLASSTYPE_ALIGN (rec) = record_align;
  555.  
  556.   return vbase_decls;
  557. }
  558.  
  559. /* Hashing of lists so that we don't make duplicates.
  560.    The entry point is `list_hash_canon'.  */
  561.  
  562. /* Each hash table slot is a bucket containing a chain
  563.    of these structures.  */
  564.  
  565. struct list_hash
  566. {
  567.   struct list_hash *next;    /* Next structure in the bucket.  */
  568.   int hashcode;            /* Hash code of this list.  */
  569.   tree list;            /* The list recorded here.  */
  570. };
  571.  
  572. /* Now here is the hash table.  When recording a list, it is added
  573.    to the slot whose index is the hash code mod the table size.
  574.    Note that the hash table is used for several kinds of lists.
  575.    While all these live in the same table, they are completely independent,
  576.    and the hash code is computed differently for each of these.  */
  577.  
  578. #define TYPE_HASH_SIZE 59
  579. struct list_hash *list_hash_table[TYPE_HASH_SIZE];
  580.  
  581. /* Here is how primitive or already-canonicalized lists' hash
  582.    codes are made.  */
  583. #define TYPE_HASH(TYPE) TREE_UID (TYPE)
  584.  
  585. /* Compute a hash code for a list (chain of TREE_LIST nodes
  586.    with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the
  587.    TREE_COMMON slots), by adding the hash codes of the individual entries.  */
  588.  
  589. int
  590. list_hash (list)
  591.      tree list;
  592. {
  593.   register int hashcode = 0;
  594.  
  595.   if (TREE_CHAIN (list))
  596.     hashcode = TYPE_HASH (TREE_CHAIN (list));
  597.   else
  598.     hashcode = 0;
  599.   if (TREE_VALUE (list))
  600.     hashcode += TYPE_HASH (TREE_VALUE (list));
  601.   else
  602.     hashcode += 1007;
  603.   if (TREE_PURPOSE (list))
  604.     hashcode += TYPE_HASH (TREE_PURPOSE (list));
  605.   else
  606.     hashcode += 1009;
  607.   return hashcode;
  608. }
  609.  
  610. /* Look in the type hash table for a type isomorphic to TYPE.
  611.    If one is found, return it.  Otherwise return 0.  */
  612.  
  613. tree
  614. list_hash_lookup (hashcode, list)
  615.      int hashcode;
  616.      tree list;
  617. {
  618.   register struct list_hash *h;
  619.   for (h = list_hash_table[hashcode % TYPE_HASH_SIZE]; h; h = h->next)
  620.     if (h->hashcode == hashcode
  621.     && TREE_VIA_VIRTUAL (h->list) == TREE_VIA_VIRTUAL (list)
  622.     && TREE_VIA_PUBLIC (h->list) == TREE_VIA_PUBLIC (list)
  623.     && TREE_PURPOSE (h->list) == TREE_PURPOSE (list)
  624.     && TREE_VALUE (h->list) == TREE_VALUE (list))
  625.       {
  626.     assert (TREE_TYPE (h->list) == TREE_TYPE (list));
  627.     assert (TREE_CHAIN (h->list) == TREE_CHAIN (list));
  628.     return h->list;
  629.       }
  630.   return 0;
  631. }
  632.  
  633. /* Add an entry to the list-hash-table
  634.    for a list TYPE whose hash code is HASHCODE.  */
  635.  
  636. void
  637. list_hash_add (hashcode, list)
  638.      int hashcode;
  639.      tree list;
  640. {
  641.   register struct list_hash *h;
  642.  
  643.   h = (struct list_hash *) obstack_alloc (&class_obstack, sizeof (struct list_hash));
  644.   h->hashcode = hashcode;
  645.   h->list = list;
  646.   h->next = list_hash_table[hashcode % TYPE_HASH_SIZE];
  647.   list_hash_table[hashcode % TYPE_HASH_SIZE] = h;
  648. }
  649.  
  650. /* Given TYPE, and HASHCODE its hash code, return the canonical
  651.    object for an identical list if one already exists.
  652.    Otherwise, return TYPE, and record it as the canonical object
  653.    if it is a permanent object.
  654.  
  655.    To use this function, first create a list of the sort you want.
  656.    Then compute its hash code from the fields of the list that
  657.    make it different from other similar lists.
  658.    Then call this function and use the value.
  659.    This function frees the list you pass in if it is a duplicate.  */
  660.  
  661. /* Set to 1 to debug without canonicalization.  Never set by program.  */
  662. int debug_no_list_hash = 0;
  663.  
  664. tree
  665. list_hash_canon (hashcode, list)
  666.      int hashcode;
  667.      tree list;
  668. {
  669.   tree t1;
  670.  
  671.   if (debug_no_list_hash)
  672.     return list;
  673.  
  674.   t1 = list_hash_lookup (hashcode, list);
  675.   if (t1 != 0)
  676.     {
  677.       obstack_free (&class_obstack, list);
  678.       return t1;
  679.     }
  680.  
  681.   /* If this is a new list, record it for later reuse.  */
  682.   list_hash_add (hashcode, list);
  683.  
  684.   return list;
  685. }
  686.  
  687. tree
  688. hash_tree_cons (via_public, via_virtual, purpose, value, chain)
  689.      int via_public, via_virtual;
  690.      tree purpose, value, chain;
  691. {
  692.   struct obstack *ambient_obstack = current_obstack;
  693.   tree t;
  694.   int hashcode;
  695.  
  696.   current_obstack = &class_obstack;
  697.   t = tree_cons (purpose, value, chain);
  698.   TREE_VIA_PUBLIC (t) = via_public;
  699.   TREE_VIA_VIRTUAL (t) = via_virtual;
  700.   hashcode = list_hash (t);
  701.   t = list_hash_canon (hashcode, t);
  702.   current_obstack = ambient_obstack;
  703.   return t;
  704. }
  705.  
  706. /* Constructor for hashed lists.  */
  707. tree
  708. hash_tree_chain (value, chain)
  709.      tree value, chain;
  710. {
  711.   struct obstack *ambient_obstack = current_obstack;
  712.   tree t;
  713.   int hashcode;
  714.  
  715.   current_obstack = &class_obstack;
  716.   t = tree_cons (NULL_TREE, value, chain);
  717.   hashcode = list_hash (t);
  718.   t = list_hash_canon (hashcode, t);
  719.   current_obstack = ambient_obstack;
  720.   return t;
  721. }
  722.  
  723. /* Similar, but used for concatenating two lists.  */
  724. tree
  725. hash_chainon (list1, list2)
  726.      tree list1, list2;
  727. {
  728.   if (list2 == 0)
  729.     return list1;
  730.   if (list1 == 0)
  731.     return list2;
  732.   if (TREE_CHAIN (list1) == NULL_TREE)
  733.     return hash_tree_chain (TREE_VALUE (list1), list2);
  734.   return hash_tree_chain (TREE_VALUE (list1),
  735.               hash_chainon (TREE_CHAIN (list1), list2));
  736. }
  737.  
  738. tree
  739. build_decl_list_1 (value)
  740.      tree value;
  741. {
  742.   tree list = NULL_TREE;
  743.  
  744.   if (TREE_CODE (value) == IDENTIFIER_NODE)
  745.     {
  746.       list = IDENTIFIER_AS_LIST (value);
  747.       if (list != NULL_TREE
  748.       && (TREE_CODE (list) != TREE_LIST
  749.           || TREE_VALUE (list) != value))
  750.     list = NULL_TREE;
  751.       else if (TREE_TYPE (value) != NULL_TREE
  752.            && TREE_CODE (TREE_TYPE (TREE_TYPE (value))) == RECORD_TYPE)
  753.     {
  754.       tree type = TREE_TYPE (TREE_TYPE (value));
  755.       if (CLASSTYPE_AS_ID_LIST (type) == NULL_TREE)
  756.         CLASSTYPE_AS_ID_LIST (type) = perm_tree_cons (NULL_TREE, value, NULL_TREE);
  757.       list = CLASSTYPE_AS_ID_LIST (type);
  758.     }
  759.     }
  760.   else if (TREE_CODE (value) == RECORD_TYPE
  761.        && TYPE_LANG_SPECIFIC (value))
  762.     list = CLASSTYPE_AS_LIST (value);
  763.  
  764.   if (list != NULL_TREE)
  765.     {
  766.       assert (TREE_CHAIN (list) == NULL_TREE);
  767.       return list;
  768.     }
  769.  
  770.   return build_decl_list (NULL_TREE, value);
  771. }
  772.  
  773. /* Look in the type hash table for a type isomorphic to
  774.    `build_tree_list (NULL_TREE, VALUE)'.
  775.    If one is found, return it.  Otherwise return 0.  */
  776.  
  777. tree
  778. list_hash_lookup_or_cons (value)
  779.      tree value;
  780. {
  781.   register int hashcode = TYPE_HASH (value);
  782.   register struct list_hash *h;
  783.   struct obstack *ambient_obstack;
  784.   tree list = NULL_TREE;
  785.  
  786.   if (TREE_CODE (value) == IDENTIFIER_NODE)
  787.     {
  788.       list = IDENTIFIER_AS_LIST (value);
  789.       if (list != NULL_TREE
  790.       && (TREE_CODE (list) != TREE_LIST
  791.           || TREE_VALUE (list) != value))
  792.     list = NULL_TREE;
  793.       else if (TREE_TYPE (value) != NULL_TREE
  794.            && TREE_CODE (TREE_TYPE (TREE_TYPE (value))) == RECORD_TYPE)
  795.     {
  796.       tree type = TREE_TYPE (TREE_TYPE (value));
  797.       if (CLASSTYPE_AS_ID_LIST (type) == NULL_TREE)
  798.         CLASSTYPE_AS_ID_LIST (type) = perm_tree_cons (NULL_TREE, value, NULL_TREE);
  799.       list = CLASSTYPE_AS_ID_LIST (type);
  800.     }
  801.     }
  802.   else if (TREE_CODE (value) == TYPE_DECL
  803.        && TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE
  804.        && TYPE_LANG_SPECIFIC (TREE_TYPE (value)))
  805.     list = CLASSTYPE_AS_ID_LIST (TREE_TYPE (value));
  806.   else if (TREE_CODE (value) == RECORD_TYPE
  807.        && TYPE_LANG_SPECIFIC (value))
  808.     list = CLASSTYPE_AS_LIST (value);
  809.  
  810.   if (list != NULL_TREE)
  811.     {
  812.       assert (TREE_CHAIN (list) == NULL_TREE);
  813.       return list;
  814.     }
  815.  
  816.   if (debug_no_list_hash)
  817.     return hash_tree_chain (value, NULL_TREE);
  818.  
  819.   for (h = list_hash_table[hashcode % TYPE_HASH_SIZE]; h; h = h->next)
  820.     if (h->hashcode == hashcode
  821.     && TREE_VIA_VIRTUAL (h->list) == 0
  822.     && TREE_VIA_PUBLIC (h->list) == 0
  823.     && TREE_PURPOSE (h->list) == 0
  824.     && TREE_VALUE (h->list) == value)
  825.       {
  826.     assert (TREE_TYPE (h->list) == 0);
  827.     assert (TREE_CHAIN (h->list) == 0);
  828.     return h->list;
  829.       }
  830.  
  831.   ambient_obstack = current_obstack;
  832.   current_obstack = &class_obstack;
  833.   list = build_tree_list (NULL_TREE, value);
  834.   list_hash_add (hashcode, list);
  835.   current_obstack = ambient_obstack;
  836.   return list;
  837. }
  838.  
  839. /* Build an association between TYPE and some parameters:
  840.  
  841.    OFFSET is the offset added to `this' to convert it to a pointer
  842.    of type `TYPE *'
  843.  
  844.    VTABLE is the virtual function table with which to initialize
  845.    sub-objects of type TYPE.
  846.  
  847.    VIRTUALS are the virtual functions sitting in VTABLE.
  848.  
  849.    CHAIN are more associations we must retain.  */
  850.  
  851. tree
  852. make_assoc (offset, type, vtable, virtuals, chain)
  853.      tree offset, type;
  854.      tree vtable, virtuals;
  855.      tree chain;
  856. {
  857.   tree assoc = make_tree_vec (4);
  858.  
  859.   TREE_TYPE (assoc) = type;
  860.   TREE_CHAIN (assoc) = chain;
  861.   if (chain)
  862.     TREE_USED (assoc) = TREE_USED (chain);
  863.  
  864.   /* n.b.: TREE_VEC_ELT (assoc, 0) <=> TREE_VALUE (assoc).  */
  865.   TREE_VEC_ELT (assoc, 0) = TYPE_MAIN_VARIANT (type);
  866.   TREE_VEC_ELT (assoc, 1) = offset;
  867.   TREE_VEC_ELT (assoc, 2) = vtable;
  868.   TREE_VEC_ELT (assoc, 3) = virtuals;
  869.   return assoc;
  870. }
  871.  
  872. tree
  873. copy_assoc (list)
  874.      tree list;
  875. {
  876.   tree assoc = copy_list (list);
  877.   tree rval = assoc;
  878.   while (assoc)
  879.     {
  880.       TREE_USED (assoc) = 0;
  881.       assoc = TREE_CHAIN (assoc);
  882.     }
  883.   return rval;
  884. }
  885.  
  886. tree
  887. assoc_value (elem, type)
  888.      tree elem;
  889.      tree type;
  890. {
  891.   tree assoc = CLASSTYPE_ASSOC (type);
  892.   tree rval = NULL_TREE;
  893.  
  894.   /* Dispose quickly of degenerate case.  */
  895.   if (elem == type)
  896.     return assoc;
  897.  
  898.   while (assoc)
  899.     {
  900.       if (elem == ASSOC_VALUE (assoc))
  901.     /* If we find it on the main spine, then
  902.        there can be no ambiguity.  */
  903.     return assoc;
  904.  
  905.       if (ASSOC_VALUE (assoc) != type)
  906.     {
  907.       tree nval = assoc_value (elem, ASSOC_TYPE (assoc));
  908.  
  909.       if (nval)
  910.         if (rval && ASSOC_TYPE (rval) != ASSOC_TYPE (nval))
  911.           /* If we find it underneath, we must make sure that
  912.          there are no two ways to do it.  */
  913.           compiler_error ("base class `%s' ambiguous in assoc_value",
  914.                   TYPE_NAME_STRING (elem));
  915.         else
  916.           rval = nval;
  917.     }
  918.       assoc = TREE_CHAIN (assoc);
  919.     }
  920.   return rval;
  921. }
  922.  
  923. tree
  924. virtual_member (elem, list)
  925.      tree elem;
  926.      tree list;
  927. {
  928.   tree t;
  929.   tree rval, nval;
  930.  
  931.   for (t = list; t; t = TREE_CHAIN (t))
  932.     if (elem == TREE_VALUE (t))
  933.       return t;
  934.   rval = 0;
  935.   for (t = list; t; t = TREE_CHAIN (t))
  936.     {
  937.       int i;
  938.       for (i = CLASSTYPE_N_BASECLASSES (TREE_TYPE (t)); i > 0; i--)
  939.     {
  940.       nval = assoc_value (elem, CLASSTYPE_BASECLASS (TREE_TYPE (t), i));
  941.       if (nval)
  942.         {
  943.           if (rval && TREE_TYPE (nval) != TREE_TYPE (rval))
  944.         abort ();
  945.           rval = nval;
  946.         }
  947.     }
  948.     }
  949.   return rval;
  950. }
  951.  
  952. void
  953. debug_dump_assoc (elem)
  954.      tree elem;
  955. {
  956.   int i;
  957.   tree virtuals;
  958.  
  959.   fprintf (stderr, "type \"%s\"; offset = %d\n",
  960.        IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (ASSOC_VALUE (elem)))),
  961.        TREE_INT_CST_LOW (ASSOC_OFFSET (elem)));
  962.   fprintf (stderr, "vtable type:\n");
  963.   dump_tree (stderr, ASSOC_TYPE (elem));
  964.   if (ASSOC_VTABLE (elem))
  965.     fprintf (stderr, "vtable decl \"%s\"\n", IDENTIFIER_POINTER (DECL_NAME (ASSOC_VTABLE (elem))));
  966.   else
  967.     fprintf (stderr, "no vtable decl yet\n");
  968.   fprintf (stderr, "virtuals:\n");
  969.   virtuals = ASSOC_VIRTUALS (elem);
  970.   if (virtuals != 0)
  971.     virtuals = TREE_CHAIN (virtuals);
  972.   i = 1;
  973.   while (virtuals)
  974.     {
  975.       tree fndecl = TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals)), 0);
  976.       fprintf (stderr, "%s [%d =? %d]\n",
  977.            IDENTIFIER_POINTER (DECL_NAME (fndecl)),
  978.            i, TREE_INT_CST_LOW (DECL_VINDEX (fndecl)));
  979.       virtuals = TREE_CHAIN (virtuals);
  980.       i += 1;
  981.     }
  982. }
  983.  
  984. char *
  985. lang_printable_name (decl)
  986.      tree decl;
  987. {
  988.   if (TREE_CODE (decl) != FUNCTION_DECL
  989.       || DECL_LANG_SPECIFIC (decl) == 0)
  990.     {
  991.       if (DECL_NAME (decl))
  992.     {
  993.       if (THIS_NAME_P (DECL_NAME (decl)))
  994.         return "this";
  995.       return IDENTIFIER_POINTER (DECL_NAME (decl));
  996.     }
  997.       return "((anonymous))";
  998.     }
  999.   if (DECL_PRINT_NAME (decl) == 0)
  1000.     {
  1001.       int print_ret_type_p
  1002.     = (!DECL_CONSTRUCTOR_P (decl)
  1003.        && !DESTRUCTOR_NAME_P (DECL_NAME (decl)));
  1004.       int temp = allocation_temporary_p ();
  1005.       char *buf = (char *)alloca (8192);
  1006.       char *name = (char *)fndecl_as_string (buf, 0, decl, print_ret_type_p);
  1007.       end_temporary_allocation ();
  1008.       DECL_PRINT_NAME (decl) = oballoc (strlen (name) + 1);
  1009.       strcpy (DECL_PRINT_NAME (decl), name);
  1010.       if (temp)
  1011.     resume_temporary_allocation ();
  1012.     }
  1013.   else if (DECL_NAME (decl) == 0)
  1014.     DECL_PRINT_NAME (decl) = "((anonymous))";
  1015.  
  1016.   return DECL_PRINT_NAME (decl);
  1017. }
  1018.  
  1019. /* Return truthvalue about whether debugger should
  1020.    output full info about this type or not.
  1021.  
  1022.    Current strategy is to permit types which define
  1023.    no member functions to be output normally.  For
  1024.    those which do define member functions, if no
  1025.    member functions have yet been output, then don't
  1026.    output the definition of the type.  If member functions
  1027.    for the type are later seen, a full definition of the
  1028.    type will eventually be output.  */
  1029. int
  1030. lang_output_debug_info (type)
  1031.      tree type;
  1032. {
  1033.   extern tree pending_vtables;
  1034.  
  1035.   if (! IS_AGGR_TYPE (type))
  1036.     return 1;
  1037.   if (TYPE_LANG_SPECIFIC (type) == 0)
  1038.     return 1;
  1039.   if (CLASSTYPE_METHOD_VEC (type) == 0)
  1040.     return 1;
  1041.  
  1042.   if (flag_minimal_debug)
  1043.     {
  1044.       /* Don't output full info about any type
  1045.      which does not have its implementation defined here.  */
  1046.       if (TYPE_VIRTUAL_P (type) && write_virtuals == 2)
  1047.     return value_member (DECL_NAME (TYPE_NAME (type)), pending_vtables) != 0;
  1048.       if (CLASSTYPE_INTERFACE_ONLY (type))
  1049.     return 0;
  1050.  
  1051.       return CLASSTYPE_ASM_WRITTEN (type);
  1052.     }
  1053.   else
  1054.     /* Can't work until GDB is modified.  */
  1055.     return 1;
  1056. }
  1057.  
  1058. /* Comparison function for sorting identifiers in RAISES lists.
  1059.    Note that because IDENTIFIER_NODEs are unique, we can sort
  1060.    them by address, saving an indirection.  */
  1061. static int
  1062. id_cmp (p1, p2)
  1063.      int *p1, *p2;
  1064. {
  1065.   return *p1 - *p2;
  1066. }
  1067.  
  1068. /* Build the FUNCTION_TYPE or METHOD_TYPE which may raise exceptions
  1069.    listed in RAISES.  */
  1070. tree
  1071. build_exception_variant (ctype, type, raises)
  1072.      tree ctype, type;
  1073.      tree raises;
  1074. {
  1075.   int i;
  1076.   tree v = TYPE_MAIN_VARIANT (type);
  1077.   tree t, t2, cname;
  1078.   tree *a = (tree *)alloca ((list_length (raises)+1) * sizeof (tree));
  1079.   int constp = TREE_READONLY (type);
  1080.   int volatilep = TREE_VOLATILE (type);
  1081.  
  1082.   if (raises && TREE_CHAIN (raises))
  1083.     {
  1084.       for (i = 0, t = raises; t; t = TREE_CHAIN (t), i++)
  1085.     a[i] = t;
  1086.       /* NULL terminator for list.  */
  1087.       a[i] = NULL_TREE;
  1088.       qsort (a, i, sizeof (tree), id_cmp);
  1089.       while (i--)
  1090.     TREE_CHAIN (a[i]) = a[i+1];
  1091.       raises = a[0];
  1092.     }
  1093.   else if (raises)
  1094.     /* do nothing.  */;
  1095.   else
  1096.     return build_type_variant (v, constp, volatilep);
  1097.  
  1098.   if (ctype)
  1099.     {
  1100.       cname = TYPE_NAME (ctype);
  1101.       if (TREE_CODE (cname) == TYPE_DECL)
  1102.     cname = DECL_NAME (cname);
  1103.     }
  1104.   else
  1105.     cname = NULL_TREE;
  1106.  
  1107.   for (t = raises; t; t = TREE_CHAIN (t))
  1108.     {
  1109.       /* See that all the exceptions we are thinking about
  1110.      raising have been declared.  */
  1111.       tree this_cname = lookup_exception_cname (ctype, cname, t);
  1112.       tree decl = lookup_exception_object (this_cname, TREE_VALUE (t), 1);
  1113.  
  1114.       if (decl == NULL_TREE)
  1115.     decl = lookup_exception_object (this_cname, TREE_VALUE (t), 0);
  1116.       /* Place canonical exception decl into TREE_TYPE of RAISES list.  */
  1117.       TREE_TYPE (t) = decl;
  1118.     }
  1119.  
  1120.   for (v = TYPE_NEXT_VARIANT (v); v; v = TYPE_NEXT_VARIANT (v))
  1121.     {
  1122.       if (TREE_READONLY (v) != constp
  1123.       || TREE_VOLATILE (v) != volatilep)
  1124.     continue;
  1125.  
  1126.       t = raises;
  1127.       t2 = TYPE_RAISES_EXCEPTIONS (v);
  1128.       while (t && t2)
  1129.     {
  1130.       if (TREE_TYPE (t) == TREE_TYPE (t2))
  1131.         {
  1132.           t = TREE_CHAIN (t);
  1133.           t2 = TREE_CHAIN (t2);
  1134.         }
  1135.       else break;
  1136.     }
  1137.       if (t || t2)
  1138.     continue;
  1139.       /* List of exceptions raised matches previously found list.
  1140.  
  1141.          @@ Nice to free up storage used in consing up the
  1142.      @@ list of exceptions raised.  */
  1143.       return v;
  1144.     }
  1145.  
  1146.   /* Need to build a new variant.  */
  1147.   v = copy_node (type);
  1148.   TYPE_NEXT_VARIANT (v) = TYPE_NEXT_VARIANT (type);
  1149.   TYPE_NEXT_VARIANT (type) = v;
  1150.   if (raises && ! TREE_PERMANENT (raises))
  1151.     {
  1152.       int temporary = allocation_temporary_p ();
  1153.       if (temporary)
  1154.     end_temporary_allocation ();
  1155.       raises = copy_list (raises);
  1156.       if (temporary)
  1157.     resume_temporary_allocation ();
  1158.     }
  1159.   TYPE_RAISES_EXCEPTIONS (v) = raises;
  1160.   return v;
  1161. }
  1162.  
  1163. /* Subroutine of make_permanent_node.
  1164.  
  1165.    Assuming T is a node build bottom-up, make it all exist on
  1166.    permanent obstack, if it is not permanent already.  */
  1167. static tree
  1168. make_deep_copy (t)
  1169.      tree t;
  1170. {
  1171.   enum tree_code code;
  1172.  
  1173.   if (t == NULL_TREE || TREE_PERMANENT (t))
  1174.     return t;
  1175.  
  1176.   switch (code = TREE_CODE (t))
  1177.     {
  1178.     case ERROR_MARK:
  1179.       return error_mark_node;
  1180.  
  1181.     case VAR_DECL:
  1182.     case PARM_DECL:
  1183.     case FUNCTION_DECL:
  1184.     case CONST_DECL:
  1185.       break;
  1186.  
  1187.     case TREE_LIST:
  1188.       {
  1189.     tree chain = TREE_CHAIN (t);
  1190.     t = copy_node (t);
  1191.     TREE_PURPOSE (t) = make_deep_copy (TREE_PURPOSE (t));
  1192.     TREE_VALUE (t) = make_deep_copy (TREE_VALUE (t));
  1193.     TREE_CHAIN (t) = make_deep_copy (chain);
  1194.     return t;
  1195.       }
  1196.  
  1197.     case TREE_VEC:
  1198.       {
  1199.     int len = TREE_VEC_LENGTH (t);
  1200.  
  1201.     t = copy_node (t);
  1202.     while (len--)
  1203.       TREE_VEC_ELT (t, len) = make_deep_copy (TREE_VEC_ELT (t, len));
  1204.     return t;
  1205.       }
  1206.  
  1207.     case INTEGER_CST:
  1208.     case REAL_CST:
  1209.     case STRING_CST:
  1210.       return copy_node (t);
  1211.  
  1212.     case COND_EXPR:
  1213.     case NEW_EXPR:
  1214.       t = copy_node (t);
  1215.       TREE_OPERAND (t, 0) = make_deep_copy (TREE_OPERAND (t, 0));
  1216.       TREE_OPERAND (t, 1) = make_deep_copy (TREE_OPERAND (t, 1));
  1217.       TREE_OPERAND (t, 2) = make_deep_copy (TREE_OPERAND (t, 2));
  1218.       return t;
  1219.  
  1220.     case SAVE_EXPR:
  1221.       t = copy_node (t);
  1222.       TREE_OPERAND (t, 0) = make_deep_copy (TREE_OPERAND (t, 0));
  1223.       return t;
  1224.  
  1225.     case MODIFY_EXPR:
  1226.     case PLUS_EXPR:
  1227.     case MINUS_EXPR:
  1228.     case MULT_EXPR:
  1229.     case TRUNC_DIV_EXPR:
  1230.     case TRUNC_MOD_EXPR:
  1231.     case MIN_EXPR:
  1232.     case MAX_EXPR:
  1233.     case LSHIFT_EXPR:
  1234.     case RSHIFT_EXPR:
  1235.     case BIT_IOR_EXPR:
  1236.     case BIT_XOR_EXPR:
  1237.     case BIT_AND_EXPR:
  1238.     case BIT_ANDTC_EXPR:
  1239.     case TRUTH_ANDIF_EXPR:
  1240.     case TRUTH_ORIF_EXPR:
  1241.     case LT_EXPR:
  1242.     case LE_EXPR:
  1243.     case GT_EXPR:
  1244.     case GE_EXPR:
  1245.     case EQ_EXPR:
  1246.     case NE_EXPR:
  1247.     case CEIL_DIV_EXPR:
  1248.     case FLOOR_DIV_EXPR:
  1249.     case ROUND_DIV_EXPR:
  1250.     case CEIL_MOD_EXPR:
  1251.     case FLOOR_MOD_EXPR:
  1252.     case ROUND_MOD_EXPR:
  1253.     case COMPOUND_EXPR:
  1254.     case PREDECREMENT_EXPR:
  1255.     case PREINCREMENT_EXPR:
  1256.     case POSTDECREMENT_EXPR:
  1257.     case POSTINCREMENT_EXPR:
  1258.     case CALL_EXPR:
  1259.       t = copy_node (t);
  1260.       TREE_OPERAND (t, 0) = make_deep_copy (TREE_OPERAND (t, 0));
  1261.       TREE_OPERAND (t, 1) = make_deep_copy (TREE_OPERAND (t, 1));
  1262.       return t;
  1263.  
  1264.     case CONVERT_EXPR:
  1265.     case ADDR_EXPR:
  1266.     case INDIRECT_REF:
  1267.     case NEGATE_EXPR:
  1268.     case BIT_NOT_EXPR:
  1269.     case TRUTH_NOT_EXPR:
  1270.     case NOP_EXPR:
  1271.     case COMPONENT_REF:
  1272.       t = copy_node (t);
  1273.       TREE_OPERAND (t, 0) = make_deep_copy (TREE_OPERAND (t, 0));
  1274.       return t;
  1275.  
  1276.       /*  This list is incomplete, but should suffice for now.
  1277.       It is very important that `sorry' does not call
  1278.       `report_error_function'.  That could cause an infinite loop.  */
  1279.     default:
  1280.       sorry ("initializer contains unrecognized tree code");
  1281.       return error_mark_node;
  1282.  
  1283.     }
  1284.   abort ();
  1285. }
  1286.  
  1287. /* Assuming T is a node built bottom-up, make it all exist on
  1288.    permanent obstack, if it is not permanent already.  */
  1289. tree
  1290. copy_to_permanent (t)
  1291.      tree t;
  1292. {
  1293.   register struct obstack *ambient_obstack = current_obstack;
  1294.   register struct obstack *ambient_saveable_obstack = saveable_obstack;
  1295.  
  1296.   if (t == NULL_TREE || TREE_PERMANENT (t))
  1297.     return t;
  1298.  
  1299.   saveable_obstack = &permanent_obstack;
  1300.   current_obstack = saveable_obstack;
  1301.  
  1302.   t = make_deep_copy (t);
  1303.  
  1304.   current_obstack = ambient_obstack;
  1305.   saveable_obstack = ambient_saveable_obstack;
  1306.  
  1307.   return t;
  1308. }
  1309.  
  1310. int
  1311. lang_simple_cst_equal (t1, t2)
  1312.      tree t1, t2;
  1313. {
  1314.   register enum tree_code code1, code2;
  1315.   int cmp;
  1316.  
  1317.   if (t1 == t2)
  1318.     return 1;
  1319.   if (t1 == 0 || t2 == 0)
  1320.     return 0;
  1321.  
  1322.   code1 = TREE_CODE (t1);
  1323.   code2 = TREE_CODE (t2);
  1324.  
  1325.   switch (code1)
  1326.     {
  1327.     case CPLUS_NEW_EXPR:
  1328.       cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  1329.       if (cmp <= 0)
  1330.     return cmp;
  1331.       return simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
  1332.  
  1333.     default:
  1334.       return -1;
  1335.     }
  1336. }
  1337.